<template>
  <div class="edit-warp">
    <el-form label-width="80px" :model="formLabelAlign" :inline="true">
      <el-form-item label="商品名称:">
        <el-input v-model="formLabelAlign.name"></el-input>
      </el-form-item>
      <el-form-item label="成本价格:">
        <el-input v-model="formLabelAlign.costPrice"></el-input>
      </el-form-item>
      <el-form-item label="规格:">
        <el-input v-model="formLabelAlign.norms"></el-input>
      </el-form-item>
      <el-form-item label="厂商名称:">
        <el-input v-model="formLabelAlign.factory"></el-input>
      </el-form-item>
      <el-form-item label="品牌名称:">
        <el-input v-model="formLabelAlign.brandName"></el-input>
      </el-form-item>
      <el-form-item label="商品类型:">
        <el-input v-model="formLabelAlign.goodsType"></el-input>
      </el-form-item>
      <el-form-item label="大单位:">
        <el-input v-model="formLabelAlign.bigUnit"></el-input>
      </el-form-item>
      <el-form-item label="小单位:">
        <el-input v-model="formLabelAlign.smallUnit"></el-input>
      </el-form-item>
      <el-form-item label="状态:">
        <el-switch
          v-model="formLabelAlign.isUsed"
          active-color="#13ce66"
          inactive-color="#ff4949"
        ></el-switch>
      </el-form-item>
    </el-form>
    <div class="edit-btn">
      <el-button type="primary" @click="editGoods">修改</el-button>
    </div>
  </div>
</template>

<script>
import { editApi } from "@/http/commodity-management/informationApi";
export default {
  name: "EditInformation",
  data() {
    return {
      formLabelAlign: {
        id: "",
        name: "",
        norms: "",
        factory: "",
        brandName: "",
        goodsType: "",
        costPrice: "",
        bigUnit: "",
        smallUnit: "",
        isUsed: "",
      },
    };
  },
  methods: {
    editGoods() {
      this.$confirm("是否确认此次操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(() => {
          editApi(this.formLabelAlign);
          this.$router.push({ path: "/goods/information" });
          this.$message({
            message: "修改成功",
            type: "success",
          });
        })
        .catch((err) => {
          console.log("获取失败", err);
        });
    },
  },
  activated() {
    let {
      name,
      norms,
      factory,
      brandName,
      goodsType,
      costPrice,
      bigUnit,
      smallUnit,
      isUsed,
      id,
    } = this.$route.query.obj;
    this.formLabelAlign.name = name;
    this.formLabelAlign.norms = norms;
    this.formLabelAlign.factory = factory;
    this.formLabelAlign.brandName = brandName;
    this.formLabelAlign.goodsType = goodsType;
    this.formLabelAlign.costPrice = costPrice;
    this.formLabelAlign.bigUnit = bigUnit;
    this.formLabelAlign.smallUnit = smallUnit;
    this.formLabelAlign.isUsed = isUsed;
    this.formLabelAlign.id = id;
  },
};
</script>

<style scoped lang="scss">
.edit-btn {
  text-align: center;
}
</style>
